package com.qing.demo.netty.demo1.aio.client;

import com.qing.demo.netty.demo1.aio.ChannelAdapter;
import com.qing.demo.netty.demo1.aio.ChannelHandler;

import java.io.IOException;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.charset.Charset;

/**
 * @author caozhipeng
 * @date 2025/7/22
 */
public class AioClientHandler  extends ChannelAdapter {
    public AioClientHandler(AsynchronousSocketChannel channel, Charset charset) {
        super(channel, charset);
    }

    @Override
    public void channelActive(ChannelHandler channelHandler) {
        try {
            System.out.println("链接报告信息："+channelHandler.channel().getRemoteAddress());
//            通知服务端链接建立成功
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void channelInactive(ChannelHandler channelHandler) {

    }

    @Override
    public void channelRead(ChannelHandler channelHandler, Object msg) {
        System.out.println("服务端接收信息："+msg+" \r\n");
        channelHandler.writeAndFlush("客户端端信息处理success \r\n");
    }
}
